/***************************************************************************************
* Copyright (c) 2014-2022 Zihao Yu, Nanjing University
*
* NEMU is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

#ifndef __SIM_H__
#define __SIM_H__

#include "common.h"
#include "paddr.h"
#include "verilated_vcd_c.h" //如果要导出vcd则需要加上
#include "Vtop.h"
#include "verilated.h"
#include "Vtop___024root.h"
#include "Vtop__Dpi.h"
#include "Vtop__Syms.h"
#include "stdio.h"

extern VerilatedContext* contextp;
extern Vtop* dut;
extern VerilatedVcdC* tfp;

enum { NPC_RUNNING, NPC_STOP, NPC_END, NPC_ABORT, NPC_QUIT };

#define NR_GPRs 32
typedef struct {
  word_t gpr[NR_GPRs];
  word_t pc;
} CPUState;

extern CPUState cpu_state;

typedef struct {
  int state;
  uint32_t halt_pc;
  uint32_t halt_ret;
} NPCState;

extern NPCState npc_state;

void cpu_sim_init();
void single_cycle();
void reset(int n);
void exec_once();

#endif
